// pages/visits/visits.js
var app = getApp()
var Utils = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tablist: ["待支付", "待接诊", "已回复", "已结束", "已退回"],
    currentData: 0,
    if_over: 0,
    accomplish :[]
  },
  //获取当前滑块的index
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    console.log(e)
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {

      return false;
    } else {
      var if_over = e.target.dataset.current
      app.util.request({
        'url': 'entry/wxapp/Tuwen.listall',
        'data': {
          openid: wx.getStorageSync('openid'),
          if_over: if_over
        },
        success: function(res) {
          console.log(res)
          that.setData({
            tuwenwz: res.data,
            if_over: if_over
          })
        },
      })
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.channel = "";
    this.uid = Utils.getUid();
    this.lock = false;
    let userInfo = wx.getStorageSync("userInfo");
    if (userInfo) {
      this.setData({
        hasUserInfo: true,
        userInfo: userInfo,
        u_name: userInfo.u_name,
        u_thumb: userInfo.u_thumb,
      });
    }
    var that = this
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      backgroundColor: bgc,
    })
    that.getalltuwenwz()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    var if_over = that.data.if_over
    if (if_over == 1) {
      app.util.request({
        'url': 'entry/wxapp/Tuwen.listall',
        'data': {
          openid: wx.getStorageSync('openid'),
          if_over: if_over
        },
        success: function(res) {
          console.log(res)
          that.setData({
            tuwenwz: res.data,
            if_over: if_over,
            currentData: if_over
          })
        },
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  getalltuwenwz() {
    var that = this
    var if_over = that.data.if_over
    app.util.request({
      'url': 'entry/wxapp/Tuwen.listall',
      'data': {
        openid: wx.getStorageSync('openid'),
        if_over: if_over
      },
      success: function(res) {
        console.log(res)
        that.setData({
          tuwenwz: res.data
        })
      },
    })
  },
  zixunxq(e) {
    var that = this
    console.log(e)
    var list = e.currentTarget.dataset
    var orders = e.currentTarget.dataset.orders
    wx.setStorage({
      key: 'userinfotype',
      data: 'user',
    })
    let userInfo = wx.getStorageSync('userInfo')
    console.log(userInfo)
    let bl_id = e.currentTarget.dataset.bl_id
    wx.setStorage({
      key: 'userInfo',
      data: userInfo,
    })
    let z_thumbs = e.currentTarget.dataset.z_thumbs //医生头像
    wx.setStorage({
      key: 'z_thumbs',
      data: z_thumbs,
    })
    let sate = 0
    wx.setStorageSync('sate', sate) //证明是用户发送的信息
    wx.setStorageSync('docroom', your)
    var my = e.currentTarget.dataset.myroom; //自己
    var your = e.currentTarget.dataset.docroom; //医生
    var dex = e.currentTarget.dataset.dex; 
    wx.setStorageSync('docroom', your)
    var nameList = {
      myName: my,
      your: your,
      bl_id: bl_id
    };
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/chatroom/chatroom?username=' + JSON.stringify(nameList) + '&list=' + JSON.stringify(list) + '&z_name=' + e.currentTarget.dataset.z_name + '&orders=' + orders + '&dex=' + dex
    })
  },
  pingjia(e) {
    console.log(e)
    var that = this
    var keywords = e.currentTarget.dataset.keywords
    var zid = e.currentTarget.dataset.zid
    var orders = e.currentTarget.dataset.orders
    var j_id = e.currentTarget.dataset.j_id
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/pingjia/pingjia?keywords=' + keywords + '&zid=' + zid + '&orders=' + orders + '&j_id=' + j_id,
    })
  }
})